<?php

//<editor-fold defaultstate="collapsed" desc="License & Copyright">
/*
 * @license
 */

/**
 *
 * @author Vladislav Kuzmin (vladislav.kuzmin@gmail.com)
 */
//</editor-fold>
class SCFileHelper {

    public function __construct() {
        
    }
    
    public static function CheckPath ($in_path, $in_create = 0) {
	$in_path = trim($in_path);
	if (empty($in_path)) {return 0;}
	
	$in_path = preg_replace('/\//', '/', $in_path);
	if (substr($in_path, 0, 1) != '/' && substr($in_path, 0, 2) != './') {$in_path = './'.$in_path;}  // make it local
	
	if ($in_path != '/') {
		$dirs = explode ('/', $in_path);
		$path = "";
		if (empty($dirs[0])) {$path = "/";}	// full
		$err = 0;
		foreach ($dirs as $dir) {
			if ($dir == '') {continue;}
			$path .= $dir."/";
			if (!is_dir($path)) {
				if ($in_create) {
					if (!mkdir($path)) {return 0;}
				} else {$err = 1;}
			}				
		}
		if (!$err) {return 1;}
	} else {
		// root folder
		if (is_dir($path)) {return 1;}
	}
	return 0;
    }
    
    public static function CreateDirectory($path) {
        return self::CheckPath($path, 1);    
    } 
    
    public static function GetFileContents($file) {
        // extend if needed
        return file_get_contents($filename);
    }
    
    public static function GetDirectoryItems ($path) {
        $ret_val = array();
        if ($pathInfo = realpath($path)) {
            
        }
        return $ret_val;
    }
    
    public static function FindFiles($path, $recursively = 0, $regex = "", $maxDepth = 0, $depth = 0) {
        if ($pathInfo = realpath($path)) {
            
        }
    }
    
}

?>
